package com.tencent.sr.iris.basic.saas.service.model.advisor;

import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardCommissionSecondResponse;
import com.tencent.sr.iris.basic.saas.common.enums.IrisAuditStatusEnum;
import com.tencent.sr.iris.basic.saas.common.utils.CommonUtils;
import com.tencent.sr.iris.user.core.service.interfaces.enums.UserLevelEnum;
import io.swagger.annotations.ApiModel;
import java.util.Optional;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@ApiModel(value = "导师身份-二级团长任务列表(佣金回滚任务)导出信息")
@Slf4j
@ColumnWidth(15)
public class AdvisorBoardCommissionExportInfo {

    @ExcelProperty(value = "序号", index = 0)
    private int num;

    @ExcelProperty(value = "开始时间", index = 1)
    private String taskPhaseStartTime;

    @ExcelProperty(value = "团长uid", index = 2)
    private String irisUid;

    @ExcelProperty(value = "union ID", index = 3)
    private String wechatUserUnionid;

    @ExcelProperty(value = "昵称", index = 4)
    private String wechatUserNickname;

    @ExcelProperty(value = "等级", index = 5)
    private String irisUidLevel;

    @ExcelProperty(value = "预估奖励订单数", index = 6)
    private String predictValidOrderNum;

    @ExcelProperty(value = "实际奖励订单数", index = 7)
    private String validOrderNum;

    @ExcelProperty(value = "预估奖励佣金", index = 8)
    private Double predictAwardAmount;

    @ExcelProperty(value = "实际奖励佣金", index = 9)
    private Double awardAmount;

    /**
     * (0.待审核 1.未完成,2审核中,3.审批驳回,4.审核通过)
     */
    @ExcelProperty(value = "审核状态", index = 10)
    private String auditStatus;

    public void readFromSearchResponseData(AdvisorBoardCommissionSecondResponse response) {
        this.setTaskPhaseStartTime(response.getTaskPhaseStartTime());
        this.setIrisUid(response.getIrisUid());
        this.setWechatUserUnionid(response.getWechatUserUnionid());
        this.setWechatUserNickname(response.getWechatUserNickname());

        String levelText = Optional.ofNullable(UserLevelEnum.getByValue(response.getIrisUidLevel()))
                .map(UserLevelEnum::getDesc).orElse(StrUtil.EMPTY);
        this.setIrisUidLevel(levelText);

        String validOrderNum = Optional.ofNullable(response.getValidOrderNum())
                .map(i -> i.toString()).orElse("0");
        this.setValidOrderNum(validOrderNum);

        String predictValidOrderNum = Optional.ofNullable(response.getPredictValidOrderNum())
                .map(i -> i.toString()).orElse("0");
        this.setPredictValidOrderNum(predictValidOrderNum);

        this.setPredictAwardAmount(CommonUtils.longToDouble(response.getPredictAwardAmount()));
        this.setAwardAmount(CommonUtils.longToDouble(response.getAwardAmount()));
        this.setAuditStatus(IrisAuditStatusEnum.getByStatus(response.getAuditStatus()));
    }

}
